import {} from '@dcloudio/uni-app'
const request:any = (params:any)=>{
  //定义基础路径
  let baseUrl = '';
  let header = {token:''}
  let token = uni.getStorageSync('TOKEN')
  if(token){
    header.token = token
  }
  return new Promise((resolve,reject)=>{
    uni.showLoading({
      title: "加载中...",
    })
    uni.request({
      url: baseUrl + params.url, //请求地址
      method: params.method || 'get', //请求方式
      data: params.data || {}, //请求带参
      header,
      success: (res)=>{//成功的回调
        resolve(res.data)
      },
      fail: (error)=>{//失败的回调
        reject(error)
      },
      complete: ()=>{//无论成功失败都执行的回调
        uni.hideLoading()
      }
    })
  })
}

//统一暴露
export default request;